import { combineReducers } from '@reduxjs/toolkit';
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import { authSlice } from '@/redux/auth/auth-slice';
import { applicationSlice } from '@/redux/application/application-slice';
import { organizeSlice } from '@/redux/organize/organize-slice';
import { departmentSlice } from '@/redux/department/department-slice';
import { userSlice } from '@/redux/user/user-slice';
import { roleSlice } from '@/redux/role/role-slice';
import { coordinationSlice } from '@/redux/coordination/coordination-slice';
import { integralReducer } from '@/pages/operations/integral/reducer/integral-reducer';
import { contactReducer } from '@/pages/operations/contact/reducer/contact-reducer';

export interface IReducerState {
  loading: boolean;
  entities: any[];
  totalCount: number;
  entity: object;
  index: number; // entity index in entities
  offset: number;
  error: any;
  key: string;
  [x: string]: any;
}

export interface IRootReducerState {
  coordination: IReducerState;
  application: IReducerState;
  organize: IReducerState;
  role: IReducerState;
  department: IReducerState;
  user: IReducerState;
  auth: any;
}

const authPersistConfig = {
  key: import.meta.env.VITE_REACT_APP_PERSIST_KEY,
  storage,
  // whitelist: ['auth'],
};

const rootReducer = combineReducers<IRootReducerState, any>({
  coordination: coordinationSlice.reducer,
  application: applicationSlice.reducer,
  organize: organizeSlice.reducer,
  department: departmentSlice.reducer,
  role: roleSlice.reducer,
  user: userSlice.reducer,
  auth: persistReducer(authPersistConfig, authSlice.reducer),
});

export default rootReducer;
